import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class webviewPage extends StatefulWidget {
  const webviewPage({Key? key}) : super(key: key);

  @override
  State<webviewPage> createState() => _webviewPageState();
}

class _webviewPageState extends State<webviewPage> {
   late WebViewController _controller;
   late String title = '加载中';
  @override
  void initState() {
    // TODO: implement initState

    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar:AppBar(
          centerTitle:true,
           title:Text(title),
           leading:IconButton(
             icon:const Icon(Icons.arrow_back_ios),
             onPressed:() async{
               bool isgoback = await _controller.canGoBack();
               if(!isgoback){
                 Navigator.pop(context);
               }else{
                 await  _controller.goBack();
               }
             },
           )


        ),
        body:Stack(
          children: [
            Positioned(
                child: WebView(
                  gestureNavigationEnabled:true,
                  initialUrl: 'https://www.jq22.com/demo/jQueryUpload201803300030/',
                  javascriptMode:JavascriptMode.unrestricted,
                  onWebViewCreated:(WebViewController web){
                      _controller = web;
                  },
                  onPageStarted:(a)=>{
                      setState(() {
                         title="加载中";
                      })
                  },
                  onPageFinished:(a) async {
                  String _title = await _controller.getTitle();
                    setState(() {
                       title = _title;
                    });

                  },
                )),

          ],
        ),
    );
  }
}


